<?
/**
 * Copyright 2007 Melange.
 *
 * This file is part of PHP-MELANGE.
 *
 * PHP-MELANGE is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * PHP-MELANGE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHP-MELANGE; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category    Melange
 * @package     php-melange
 * @subpackage  cms
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 *
 */
?>
<?=$this->header()?>


    <?=$this->menu("menus")?>


    <h1><?=$this->message("label.item.header", _Menu::BUNDLE)?></h1>


    <? /* Breadcrums route & page info display */ ?>
    <?=$this->route(
        array_merge(
            array(array(
                "name"=>$this->message("label.header", _Menu::BUNDLE),
                "href"=>$this->path()."menu/list"
            )),
            $this->menuRoute($this->itemListForm->getParentId()),
            array(array(
                "name"=>$this->message("label.items", _Menu::BUNDLE) . " " .
                    $this->message("title.for", _Core::BUNDLE) . " " .
                    strtolower($this->message("label.item". ($this->itemListForm->getParentId() == 0 ? "" : ".item"), _Menu::BUNDLE)) . " " .
                    " \"" . $this->menuitems($this->itemListForm)->getName() ."\""
            ))           
        ),
        $this->itemListForm,                             // ListForm (for page info, see float right)
        $this->menuitems($this->itemListForm)->getRows() // The total amount of items
    )?>


    <? /* Show status messages */ ?>
    <?=$this->messages(_Core::BUNDLE)?>


    <? /* Show error messages */ ?>
    <?=$this->errors(null, _Core::BUNDLE)?>


    <form id="<?=get_class($this->itemListForm)?>"
          method="post"
          action="menu/item/list"
          onsubmit="return confirmDelete('<?=$this->message("message.confirm.delete", _Core::BUNDLE)?>', this)">


        <? /* Show the Search & Filter Panel */ ?>
        <?=$this->panel(
            $this->path() . "menu/item/edit?itemI18n->menuItem->menuId=" .
                $this->itemListForm->getId() . "&itemI18n->menuItem->parentId=" .
                    $this->itemListForm->getParentId(), // Add New URL
            $this->itemListForm,                        // ListForm
            array(                                      // Filter fields
                MenuItemI18nPeer::NAME=>$this->message("prompt.item.name", _Menu::BUNDLE),
                MenuItemI18nPeer::INSERT_DATE=>$this->message("choose.created", _Core::BUNDLE),
                MenuItemI18nPeer::MODIFIED_DATE=>$this->message("choose.modified", _Core::BUNDLE),
                MenuItemI18nPeer::ACTIVE=>$this->message("choose.active", _Core::BUNDLE)
            ),
            // Only show languages when a default language menu
            $this->menuitems($this->itemListForm)->getMenu()->getLanguageCode() ==
                $this->param(_Core::DEFAULT_LANGUAGE)
        )?>


        <? /* Start output buffering in case there are no results */ ?>
        <?$this->start()?>


        <table  cellspacing="0" cellpadding="0" class="list">
        <tr>
            <th class="checkbox"></th>

            <? /* Hide i18n if disabled */ ?>
            <? if($this->param(_Core::I18N)): ?>
                <th class="narrow" title="<?=$this->message("title.language", _Core::BUNDLE)?>">
                    <?=$this->message("label.language", _Core::BUNDLE)?>
                </th>
            <? endif; ?>

            <th>
                <?=$this->TH(
                    $this->itemListForm,                                 // ListForm
                    MenuItemI18nPeer::NAME,                           // Sort Field
                    $this->message("prompt.item.name", _Menu::BUNDLE) // Header Name
                )?>
            </th>
            <th class="narrow">
                <?=$this->TH(
                    $this->itemListForm,                            // ListForm
                    "count",                                        // Sort Field
                    $this->message("label.items", _Menu::BUNDLE) // Header Name
                )?>
            </th>
            <th class="narrow">
                <?=$this->TH(
                    $this->itemListForm,                           // ListForm
                    MenuItemI18nPeer::MODIFIED_DATE,            // Sort Field
                    $this->message("choose.modified", _Core::BUNDLE) // Header Name
                )?>
            </th>
            <th class="narrow">
                <?=$this->TH(
                    $this->itemListForm,                          // ListForm
                    MenuItemI18nPeer::INSERT_DATE,             // Sort Field
                    $this->message("choose.created", _Core::BUNDLE) // Header Name
                )?>
            </th>
            <th class="narrow" title="<?=$this->message("title.active", _Core::BUNDLE)?>">
                <?=$this->TH(
                    $this->itemListForm,                        // ListForm
                    MenuItemI18nPeer::ACTIVE,                // Sort Field
                    $this->message("label.active", _Core::BUNDLE) // Header Name
                )?>
            </th>

            <? /* Only show available move arrows & available languages when language selectbox is on ALL */ ?>
            <? if(strlen($this->itemListForm->getLanguage()) == 0 &&
                    strlen($this->itemListForm->getQuery()) == 0): ?>

                <th class="narrow" title="<?=$this->message("title.order", _Core::BUNDLE)?>">
                    <?=$this->TH(
                        $this->itemListForm,                        // ListForm
                        MenuItemPeer::POSITION,                  // Sort Field
                        $this->message("label.order", _Core::BUNDLE), // Header Name
                        "ASC"
                    )?>
                </th>

                <? /* Hide i18n if disabled */ ?>
                <? if($this->param(_Core::I18N) && $this->menuitems($this->itemListForm)->getMenu()->getLanguageCode() ==
                        $this->param(_Core::DEFAULT_LANGUAGE)): ?>
                    <th class="narrow" title="<?=$this->message("title.language.available", _Core::BUNDLE)?>">
                        <?=$this->message("label.language.available", _Core::BUNDLE)?>
                    </th>
                <? endif; ?>

            <? endif; ?>

            <th class="buttons"></th>
        </tr>

        <? foreach($this->menuitems($this->itemListForm)->getItems() as $itemI18n): ?>

            <tr class="ctrl">
                <td class="checkbox">
                    <input type="checkbox"
                           name="items[]"
                           value="<?=$itemI18n->getMenuItemI18nId()?>"
                           <?=in_array($itemI18n->getMenuItemI18nId(), $this->itemListForm->getItems()) ? " checked=\"checked\"" : ""?> />
                </td>

                <? /* Hide i18n if disabled */ ?>
                <? if($this->param(_Core::I18N)): ?>
                    <td title="<?=$this->message("title.language", _Core::BUNDLE)?>">

                        <img src="static.php?file=<?=$this->image("cms/core/view/gfx/flag/".strtolower($itemI18n->getLanguage()->getCode()).".png")?>"
                             width="16" height="11" alt="<?=$itemI18n->getLanguage()->getName()?>"
                             title="<?=$itemI18n->getLanguage()->getName()?>" />

                    </td>
                <? endif; ?>
                
                <td><?=$itemI18n->getName()?></td>
                <td title="<?=$this->message("title.items", _Menu::BUNDLE)?>">
                    <a title="<?=$this->message("title.items", _Menu::BUNDLE)?>" href="menu/item/list?parentId=<?=$itemI18n->getMenuItemId()?>">
                        <?=$itemI18n->getCount()?>
                    </a>
                </td>
                <td title="<?=$this->message("title.modified", _Core::BUNDLE)?> <?=$itemI18n->getModifiedDate(_Core::FORMAT_DATETIME)?>">
                    <?=$itemI18n->getModifiedDate(_Core::FORMAT_DATE)?>
                </td>
                <td title="<?=$this->message("title.created", _Core::BUNDLE)?> <?=$itemI18n->getInsertDate(_Core::FORMAT_DATETIME)?>">
                    <?=$itemI18n->getInsertDate(_Core::FORMAT_DATE)?>
                </td>
                <td title="<?=$this->message("title.active", _Core::BUNDLE)?>">
                    <?=$this->message("label." . ($itemI18n->getActive() ? "yes" : "no"), _Core::BUNDLE)?>
                </td>

                <? /* Only show available move arrows & available languages when language selectbox is on ALL */ ?>
                <? if(strlen($this->itemListForm->getLanguage()) == 0 &&
                      strlen($this->itemListForm->getQuery()) == 0): ?>

                    <td title="<?=$this->message("title.move", _Core::BUNDLE)?>">

                        <? if($itemI18n->getMenuItem()->getPosition() > 1): ?>
                            <input type="image" onclick="moveup(<?=$itemI18n->getMenuItemI18nId()?>, this.form)"
                                   src="static.php?file=<?=$this->image("cms/core/view/gfx/arrow_up.png")?>" alt=""
                                   alt="<?=$this->message("title.move.up", _Core::BUNDLE)?>"
                                   title="<?=$this->message("title.move.up", _Core::BUNDLE)?>. <?=$this->message("title.move", _Core::BUNDLE)?>" />
                        <? endif; ?>

                        <? if($itemI18n->getMenuItem()->getPosition() < $itemI18n->getMenuItem()->getMaxPosition()): ?>
                            <input type="image" onclick="movedown(<?=$itemI18n->getMenuItemI18nId()?>, this.form)"
                                   src="static.php?file=<?=$this->image("cms/core/view/gfx/arrow_down.png")?>"
                                   alt="<?=$this->message("title.move.down", _Core::BUNDLE)?>"
                                   title="<?=$this->message("title.move.down", _Core::BUNDLE)?>. <?=$this->message("title.move", _Core::BUNDLE)?>" />
                        <? endif; ?>

                    </td>

                    <? /* Hide i18n if disabled */ ?>
                        <? if($this->param(_Core::I18N) && $this->menuitems($this->itemListForm)->getMenu()->getLanguageCode() ==
                            $this->param(_Core::DEFAULT_LANGUAGE)): ?>
                        <td title="<?=$this->message("title.language.available", _Core::BUNDLE)?>">

                            <? foreach($itemI18n->getAvailableLanguages() as $language) { ?>
                                <a href="menu/item/edit?itemI18n->menuItemId=<?=$itemI18n->getMenuItemId()?>&amp;itemI18n->languageCode=<?=$language->getCode()?>&amp;itemI18n->menuItem->menuId=<?=$this->itemListForm->getId()?>">
                                    <img src="static.php?file=<?=$this->image("cms/core/view/gfx/flag/".strtolower($language->getCode()).".png")?>"
                                         width="16" height="11"
                                         alt="<?=$language->getName()?>"
                                         title="<?=$this->message("title.translate.item", _Core::BUNDLE)?> (<?=$language->getName()?>)."
                                    /></a>
                            <? } ?>

                        </td>
                    <? endif; ?>

                <? endif; ?>
                
                <td class="buttons">

                    <input type="button"
                           onclick="to('menu/item/edit?itemI18n->menuItemI18nId=<?=$itemI18n->getMenuItemI18nId()?>')"
                           class="button"
                           value="<?=$this->message("button.edit", _Core::BUNDLE)?>" />
                    <input type="button"
                           onclick="del(<?=$itemI18n->getMenuItemI18nId()?>, '<?=get_class($this->itemListForm)?>')"
                           class="button"
                           value="<?=$this->message("button.delete", _Core::BUNDLE)?>" />

                </td>
            </tr>

            <? /* Loop through the foreign languages when i18n enabled & language selectbox is on ALL & menu is default language */?>
            <? if($this->param(_Core::I18N) &&
                  strlen($this->itemListForm->getLanguage()) == 0 &&
                  strlen($this->itemListForm->getQuery()) == 0 &&
                  $this->menuitems($this->itemListForm)->getMenu()->getLanguageCode() == $this->param(_Core::DEFAULT_LANGUAGE)): ?>

                <? foreach($itemI18n->getForeignItem18ns(
                    $this->param(_Core::DEFAULT_LANGUAGE),
                    MenuItemI18nPeer::NAME,
                    $this->itemListForm->getDirection()) as $i18nItem): ?>

                <tr class="ctrlsub">
                    <td class="checkbox">

                        <input type="checkbox"
                           name="items[]"
                           value="<?=$i18nItem->getMenuItemI18nId()?>"
                           <?=in_array($i18nItem->getMenuItemI18nId(), $this->itemListForm->getItems()) ? " checked=\"checked\"" : ""?> />

                    </td>
                    <td title="<?=$this->message("title.language", _Core::BUNDLE)?>">

                        <img src="static.php?file=<?=$this->image("cms/core/view/gfx/flag/".strtolower($i18nItem->getLanguage()->getCode()).".png")?>"
                             width="16" height="11"
                             alt="<?=$i18nItem->getLanguage()->getName()?>"
                             title="<?=$this->message("title.translation", _Core::BUNDLE)?> (<?=$i18nItem->getLanguage()->getName()?>)" />

                    </td>
                    <td>

                        <img src="static.php?file=<?=$this->image("cms/core/view/gfx/arrow_merge.png")?>"
                             title="<?=$this->message("title.translation", _Core::BUNDLE)?> (<?=$i18nItem->getLanguage()->getName()?>)"
                             width="16" height="16" alt="" />
                        <?=$i18nItem->getName()?>

                    </td>
                    <td></td>
                    <td title="<?=$this->message("title.modified", _Core::BUNDLE)?> <?=$i18nItem->getModifiedDate(_Core::FORMAT_DATETIME)?>">
                        <?=$i18nItem->getModifiedDate(_Core::FORMAT_DATE)?>
                    </td>
                    <td title="<?=$this->message("title.created", _Core::BUNDLE)?> <?=$i18nItem->getInsertDate(_Core::FORMAT_DATETIME)?>">
                        <?=$i18nItem->getInsertDate(_Core::FORMAT_DATE)?>
                    </td>
                    <td title="<?=$this->message("title.active", _Core::BUNDLE)?>">
                        <?=$this->message("label." . ($i18nItem->getActive() ? "yes" : "no"), _Core::BUNDLE)?>
                    </td>

                    <? /* Only show move arrows & available languages when language selectbox is on ALL) */ ?>
                    <? if(strlen($this->itemListForm->getLanguage()) == 0 && strlen($this->itemListForm->getQuery()) == 0): ?>
                        <td></td>
                        <td></td>
                    <? endif; ?>

                    <td class="buttons">

                        <input type="button"
                               onclick="to('menu/item/edit?itemI18n->menuItemI18nId=<?=$i18nItem->getMenuItemI18nId()?>')"
                               class="button"
                               value="<?=$this->message("button.edit", _Core::BUNDLE)?>" />

                        <input type="button"
                               onclick="del(<?=$i18nItem->getMenuItemI18nId()?>, '<?=get_class($this->itemListForm)?>')"
                               class="button"
                               value="<?=$this->message("button.delete", _Core::BUNDLE)?>" />

                    </td>
                </tr>
                <? endforeach; ?>

            <? endif; ?>

        <? endforeach; ?>

        </table>


        <? /* Edit/Action Bar for checkboxed */ ?>
        <?=$this->edit(
            $this->itemListForm, // ListForm
            array(               // The actions
                "activate"=>$this->message("choose.activate", _Core::BUNDLE),
                "deactivate"=>$this->message("choose.deactivate", _Core::BUNDLE),
                "delete"=>$this->message("choose.delete", _Core::BUNDLE)
            )
        )?>


        <? /* End output buffering */ ?>
        <?$this->end(
            $this->itemListForm,
            $this->path()."menu/item/edit?itemI18n->menuItem->menuId=".$this->itemListForm->getId() .
                "&itemI18n->menuItem->parentId=" . $this->itemListForm->getParentId(),
            $this->menuitems($this->itemListForm)->getRows()
        )?>


    </form>

<?=$this->footer()?>